<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/18
 * Time: 14:34
 */

namespace app\mall\controller;


use app\admin\model\HomeAdvertisement;
use app\admin\model\HomeIcon;
use app\admin\model\HomeImages;
use app\admin\model\HomeLabel;

class Home extends Base
{
    //首页轮播
    public function homeImage(){
        $data = HomeImages::where('status',1)
            ->field('id,title,image,url,sort')->order('sort desc')->select()->each(function ($item){
                $item->image = $this->url.$item->image;
            })->toArray();
        if (!$data){
            return json(['code'=>0,'msg'=>'无数据']);
        }
        return json(['code'=>1,'msg'=>'返回成功','data'=>$data]);
    }
    //    首页广告
    public function homeAdvertisement(){
        $data = HomeAdvertisement::where('id','in',[1,2,3])->order('id asc')->select()->each(function ($item){
            $item->image = $this->url.$item->image;
        })->toArray();
        if (!$data){
            return json(['code'=>0,'msg'=>'无数据']);
        }
        return json(['code'=>1,'msg'=>'返回成功','data'=>$data]);
    }

    public function homeIcon(){
        $data = HomeIcon::order('sort desc')->select()->each(function ($item){
            $item->image = $this->url.$item->image;
        })->toArray();
        if (!$data){
            return json(['code'=>0,'msg'=>'无数据']);
        }
        return json(['code'=>1,'msg'=>'返回成功','data'=>$data]);
    }

    public function homeLabel(){
        $data = HomeLabel::order('sort desc')->select()->each(function ($item){
            $item->image = $this->url.$item->image;
            $item->image_selection = $this->url.$item->image_selection;
        })->toArray();
        if (!$data){
            return json(['code'=>0,'msg'=>'无数据']);
        }
        return json(['code'=>1,'msg'=>'返回成功','data'=>$data]);
    }


}